package org.xiaozhiying.enumrate;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public enum CityWeatherEnum {
    // 定义枚举的值
    CHANGSHA(430100, "http://restapi.amap.com/v3/weather/weatherInfo?city=430100&key=2dc52ed02e191274260c9e25c295fa61"),
    ZHUZHOU(430200, "http://restapi.amap.com/v3/weather/weatherInfo?city=430200&key=2dc52ed02e191274260c9e25c295fa61"),
    XIANGTAN(430300, "http://restapi.amap.com/v3/weather/weatherInfo?city=430300&key=2dc52ed02e191274260c9e25c295fa61"),
    HENGYANG(430400, "http://restapi.amap.com/v3/weather/weatherInfo?city=430400&key=2dc52ed02e191274260c9e25c295fa61"),
    SHAOYANG(430500, "http://restapi.amap.com/v3/weather/weatherInfo?city=430500&key=2dc52ed02e191274260c9e25c295fa61"),
    YUEYANG(430600, "http://restapi.amap.com/v3/weather/weatherInfo?city=430600&key=2dc52ed02e191274260c9e25c295fa61"),
    CHANGDE(430700, "http://restapi.amap.com/v3/weather/weatherInfo?city=430700&key=2dc52ed02e191274260c9e25c295fa61"),
    ZHANGJIAJIE(430800, "http://restapi.amap.com/v3/weather/weatherInfo?city=430800&key=2dc52ed02e191274260c9e25c295fa61"),
    YIYANG(430900, "http://restapi.amap.com/v3/weather/weatherInfo?city=430900&key=2dc52ed02e191274260c9e25c295fa61"),
    CHENGZHOU(431000, "http://restapi.amap.com/v3/weather/weatherInfo?city=431000&key=2dc52ed02e191274260c9e25c295fa61"),
    YONGZHOU(431100, "http://restapi.amap.com/v3/weather/weatherInfo?city=431100&key=2dc52ed02e191274260c9e25c295fa61"),
    HUAIHUA(431200, "http://restapi.amap.com/v3/weather/weatherInfo?city=431200&key=2dc52ed02e191274260c9e25c295fa61"),
    LOUDI(431300, "http://restapi.amap.com/v3/weather/weatherInfo?city=431300&key=2dc52ed02e191274260c9e25c295fa61"),
    XIANGXI(433100, "http://restapi.amap.com/v3/weather/weatherInfo?city=433100&key=2dc52ed02e191274260c9e25c295fa61");

    private int cityCode;

    private String url;

    // 构造方法
    private CityWeatherEnum(int cityCode, String url) {
        this.cityCode = cityCode;
        this.url = url;
    }

    private int getCityCode() {
        return cityCode;
    }
    // 根据程序编码查询URL
    public static String getUrl(int cityCode) {
        for (CityWeatherEnum cityWeatherEnum : CityWeatherEnum.values()) {
            if (cityWeatherEnum.getCityCode() == cityCode) {
                return cityWeatherEnum.url;
            }
        }
        return null;
    }

    public static List<String> getAllUrl() {
        List<String> list = new LinkedList<>();
        list.add(CityWeatherEnum.getUrl(430100));
        list.add(CityWeatherEnum.getUrl(430200));
        list.add(CityWeatherEnum.getUrl(430300));
        list.add(CityWeatherEnum.getUrl(430400));
        list.add(CityWeatherEnum.getUrl(430500));
        list.add(CityWeatherEnum.getUrl(430600));
        list.add(CityWeatherEnum.getUrl(430700));
        list.add(CityWeatherEnum.getUrl(430800));
        list.add(CityWeatherEnum.getUrl(430900));
        list.add(CityWeatherEnum.getUrl(431000));
        list.add(CityWeatherEnum.getUrl(431100));
        list.add(CityWeatherEnum.getUrl(431200));
        list.add(CityWeatherEnum.getUrl(431300));
        list.add(CityWeatherEnum.getUrl(433100));
        return list;
    }
}
